if(!$){
	alert('need jquery');
}

if(!this.r929){
	this.r929	=	{};
}

(function(){
	
	var iframeMap	=	{};
	var iframeReadyCallBackMap	=	{};
	var iframeWindowMap	=	{};
	var iframeBodyMap	=	{};
	
	var divi	=	{};
	divi.addIframe	=	function(src, iframeId, readyCallBack){
		var iframe	=	$('<iframe style="width:0px;height:0px;overflow:hidden;" src="'+src+'#'+iframeId+'"></iframe>');
		iframeMap[iframeId]	=	iframe;
		iframeReadyCallBackMap[iframeId]	=	readyCallBack;
		$('body').append(iframe);
	};
	
	divi.removeIframe	=	function(iframeId){
		if(!iframeMap[iframeId]){
			return;
		}
		iframeMap[iframeId].remove();
		delete iframeMap[iframeId];
		delete iframeReadyCallBackMap[iframeId];
		if(iframeBodyMap[iframeId]){
			iframeBodyMap[iframeId].remove();
			delete iframeBodyMap[iframeId];
		}
		if(iframeWindowMap[iframeId]){
			//iframeWindowMap[iframeId].r929.divi.destroy();
			delete iframeWindowMap[iframeId];
		}
	};
	
	divi.iframeReady	=	function(iframeId, iframeBody, iframeWindow){
		if(!iframeMap[iframeId]){
			iframeWindow.r929.divi.destroy();
			return;
		}
		iframeWindowMap[iframeId]	=	iframeWindow;
		iframeBodyMap[iframeId]	=	iframeBody;
		
		if(iframeReadyCallBackMap[iframeId] && typeof(iframeReadyCallBackMap[iframeId]) == "function"){
			iframeReadyCallBackMap[iframeId](iframeId, iframeBody, iframeWindow);
		}
	};
	
	divi.notice	=	function(token, data){
		if(divi.notice.searchTarget["notice_"+token] && typeof(divi.notice.searchTarget["notice_"+token]) == "function"){
			divi.notice.searchTarget["notice_"+token](data);
		}
	};
	divi.notice.searchTarget	=	window;
	
	divi.broadcast	=	function(token, data){
		divi.notice(token, data);
		for(var p in iframeWindowMap){
			iframeWindowMap[p].r929.divi.notice(token, data);
		}
	};
	
	
	this.r929.divi	=	divi;
	
	this.addIframe	=	divi.addIframe;
	this.removeIframe	=	divi.removeIframe;
	this.broadcast	=	divi.broadcast;
})();